var http=require('http')
var url = require('url');
var fs = require('fs');


http.createServer(function (request,response) {

    var urlObj = url.parse(request.url,true);
    console.log(urlObj.pathname);
    console.log(__dirname);

    if(urlObj.pathname=='/index'){
        fs.readFile("../template/index.html",function (error,data) {
            response.writeHead(200,{'Content-Type':'text/html;charset=utf8'})
            response.end(data.toString());
        })
    }

    if(urlObj.pathname.indexOf('/public')>0){
        fs.readFile("../static"+urlObj.pathname,function (error,data) {
            response.writeHead(200,{'Content-Type':'text/plain;charset=utf8'})
            response.end(data);
        })
    }


}).listen(3000,function () {
    console.log("the server is running on port 3000")
})